#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e5 + 10, M = 2e6 + 10;

bool st[N];
struct node{
	int x, y, z;
}a[M];
int hi[N];

int fa[N];

int pos;
LL cnt, ret;
int n, m;

vector<PII> edges[N];

void dfs(int u)
{
	st[u] = true;
	cnt++;
	for(auto v : edges[u])
	{
		int x = v.first, y = v.second;
		++pos;
		a[pos].x = u; a[pos].y = x; a[pos].z = y;
		if(!st[x]) dfs(x);
	}
}

int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

bool cmp(node& a, node& b)
{
	int y1 = a.y, z1 = a.z, y2 = b.y, z2 = b.z;
	if(hi[y1] != hi[y2]) return hi[y1] > hi[y2];
	else return z1 < z2;
}

void kruskal()
{
	for(int i = 1; i <= n; i++) fa[i] = i;
	sort(a + 1, a + 1 + pos, cmp);
	for(int i = 1; i <= pos; i++)
	{
		int x = a[i].x, y = a[i].y, z = a[i].z;
		int fx = find(x), fy = find(y);
		if(fx != fy)
		{
			ret += z;
			fa[fx] = fy;
		}
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) 
	{
		cin >> hi[i];
	}
	for(int i = 1; i <= m; i++)
	{
		int x, y, z; cin >> x >> y >> z;
		if(hi[x] >= hi[y]) edges[x].push_back({y, z});
		if(hi[y] >= hi[x]) edges[y].push_back({x, z});
	}
	
	dfs(1);
	cout << cnt << " ";
	kruskal();
	cout << ret << endl;
	return 0;
}
